﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}

@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="dept-form">
                <div class="select-list">
                    <ul>
                        <li>
                            菜单名称：<input id="menuName" name="MenuName" type="text" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:dept:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="treeTable"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        var options = {
            id: "treeTable",
            code: "id",
            parentCode: "parentId", // 用于设置父子关系
            uniqueId: "id",
            expandAll: false,
            expandFirst: false,
            url: "/SystemManage/Menu/GetListJson",
            createUrl: "/SystemManage/Menu/MenuForm",
            updateUrl: "/SystemManage/Menu/MenuForm",
            removeUrl: "/SystemManage/Menu/DeleteFormJson?ids={id}",
            modalName: "菜单", width: '20', widthUnit: '%',
            columns: [
                //{ field: 'selectItem', radio: true, width: '20', widthUnit: '%', },
                { field: 'selectItem', radio: true },
                {
                    title: '菜单名称', field: 'menuName', width: '10', widthUnit: '%',
                    formatter: function (value, row, index) {
                        if ($.common.isEmpty(row.menuIcon)) {
                            return row.menuName;
                        } else {
                            return '<i class="' + row.menuIcon + '"></i> <span class="nav-label">' + row.menuName + '</span>';
                        }
                    }
                },
                { field: 'menuSort', title: '排序', align: "left", width: '10', widthUnit: '%' },
                { field: 'menuUrl', title: '请求地址', align: "left", width: '20', widthUnit: '%'},
                {
                    field: 'menuType', title: '类型', align: "left", width: '10', widthUnit: '%',
                    formatter: function (value, item, index) {
                        //菜单类型(1目录 2页面 3按钮)
                        if (item.menuType == 1) {
                            return '<span class="label label-success">目录</span>';
                        }
                        else if (item.menuType == 2) {
                            return '<span class="label label-primary">菜单</span>';
                        }
                        else if (item.menuType == 3) {
                            return '<span class="label label-warning">按钮</span>';
                        }
                    }
                },
                { field: 'authorize', title: '权限标识', align: "left", width: '10', widthUnit: '%' },
                {
                    title: '操作', align: "left", width: '10', widthUnit: '%',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs  href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);
    });
</script>